package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.entity.config.beauty.BeautyModifySkillResult;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_BEAUTY_SKILL_MODIFY, desc = "美女技能改装(随机技能)")
public class BeautySkillModifyCmd extends AbstractCommand {

	int beautyId;

	int skillPos;

	boolean isCustomize;

	BeautyModifySkillResult result;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BeautyProto.BeautySkillModifyReqMsg reqMsg = BeautyProto.BeautySkillModifyReqMsg.parseFrom(packet.getBytes());
		beautyId = reqMsg.getBeautyId();
		skillPos = reqMsg.getSkillPos();
		isCustomize = reqMsg.getIsCustomize();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(player.isRequestCmdTooFast(Protocol.S_BEAUTY_SKILL_MODIFY, 200)){
			result =  new BeautyModifySkillResult();
			result.setRet(GameErrorCode.E_REQUEST_TOO_FAST);
			return;
		}
		result = player.getModule(BeautyModule.class).beautyModifySkill(beautyId, skillPos, isCustomize,false);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(null != result) {
			BeautyProto.BeautySkillModifyRespMsg.Builder respMsg = BeautyProto.BeautySkillModifyRespMsg.newBuilder();
			respMsg.setRet(result.getRet());
			if(0 == result.getRet()){
				respMsg.setIsReplace(result.isReplace());
				BeautyProto.BeautySkillTempMsg.Builder skillMsg = BeautyPb.parseBeautySkillTempMsg(result.getBeautySkill());
				if(null != skillMsg) {
					respMsg.setBeautySkill(skillMsg);
				}
				respMsg.setCurValue(result.getCurValue());
			}
			player.sendPacket(Protocol.U_BEAUTY_SKILL_MODIFY, respMsg);
		}
	}
}
